package cn.com.haopy.yue.ai.db.service.hos.impl;

import cn.com.haopy.yue.ai.db.entity.arisk.AIRiskOrder;
import cn.com.haopy.yue.ai.db.mapper.arisk.AIRiskOrderMapper;
import cn.com.haopy.yue.ai.db.service.BaseServiceImpl;
import cn.com.haopy.yue.ai.db.service.hos.AIRiskOrderService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Objects;

/**
 * @Description: TODO
 * @Author DuTao
 * @Date 2025/3/28 8:56
 */
@Service
public class AIRiskOrderServiceImpl extends BaseServiceImpl<AIRiskOrderMapper, AIRiskOrder> implements AIRiskOrderService {
    @Override
    public AIRiskOrder getByOrderNo(String orderNo) {
        QueryWrapper<AIRiskOrder> queryWrapper = new QueryWrapper<>();

        queryWrapper.lambda().eq(AIRiskOrder::getOrderNo, orderNo);

        return super.getOne(queryWrapper);
    }

    @Override
    public Page<AIRiskOrder> querySelective(Integer userId, String orderNo, Integer page, Integer limit, String sort, String order) {

        QueryWrapper<AIRiskOrder> queryWrapper = new QueryWrapper<>();
        //queryWrapper.lambda().eq(AIRiskPapers::getIsSubmit, Boolean.TRUE);
        if (Objects.nonNull(userId)) {
            queryWrapper.lambda().eq(AIRiskOrder::getUserId, userId);
        }

        if (StringUtils.hasText(orderNo)) {
            queryWrapper.lambda().like(AIRiskOrder::getOrderNo, orderNo);
        }
        if (StringUtils.hasText(sort) && StringUtils.hasText(order)) {
            queryWrapper.orderBy(true, "asc".equals(order), sort);
        }
        return super.page(new Page<>(page, limit), queryWrapper);


    }
}
